//
//  UIButton+XTExtension.m
//  newBooks
//
//  Created by 张 on 2018/11/24.
//  Copyright © 2018年 pro2. All rights reserved.
//

#import "UIButton+XTExtension.h"
#import <objc/runtime.h>

@implementation UIButton (XTExtension)

- (void)setAction:(void (^)(void))action{
    objc_setAssociatedObject(self, "ButtonAction", action, OBJC_ASSOCIATION_COPY_NONATOMIC);
    [self addTarget:self action:@selector(xtButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)xtButtonAction:(UIButton *)button{
    void (^action)(void) = objc_getAssociatedObject(self, "ButtonAction");
    if (action) {
        action();
    }
}

@end
